package com.thirteen;

import java.util.Vector;

public class VectorTestImprove {
    private static Vector<Integer> vector = new Vector<Integer>();

    public static void main(String[] args) {
        for(int i = 0; i<10; i++){
            vector.add(i);
        }

        Thread removeThread = new Thread(new Runnable(){
            @Override
            public void run(){
                synchronized (vector){
                    for (int i=0; i<vector.size();i++) {
                        System.out.println(" vector has " +String.valueOf(vector.size())+ " elements!");
                        vector.remove(i);
                        System.out.println("Vector just now has NO." + String.valueOf(i) +" element removed!");
                    }
                }
            }
        });

        Thread printThread = new Thread(new Runnable(){
            @Override
            public void run(){
                synchronized (vector) {
                    for (int i = 0; i< 10;i++){
                        System.out.println((vector.get(i)));
                    }
                }
            }
        });

        removeThread.start();
        printThread.start();
        while (Thread.activeCount() > 20);
    }
}
